﻿using System;
using System.Text;

namespace GPS.GPSLanguage
{
    class SentenceCountToken
    {
        internal static void ParseLanguage(GPSData gpsData, System.Collections.Queue q)
        {
            String sentCountToken = (string)q.Dequeue();
            int sentCount = 0;
            try
            {
                if(sentCountToken.Length>0)
                    sentCount = int.Parse(sentCountToken);
            }
            catch { }

            if (gpsData.SentenceCount!= 0 && sentCount != gpsData.SentenceCount)
            {
                gpsData.ClearData();
            }

            gpsData.SetSentenceCount(sentCount);

            switch (gpsData.MessageType)
            {
                case MessageType.GPGSV:
                    SentenceNumberToken.ParseLanguage(gpsData, q);
                    break;
                default:
                    throw new InvalidLanguageException("How did you get here?");
            }

        }
    }
}
